사이트 내 전체검색
PHP
썸네일 워터마크를 한글로 찍어주기 (그누보드) php 워터마크 소스
로빈아빠
https://cmd.kr/php/562 URL이 복사되었습니다.

본문

 

관리자님의 갤러리 게시판에서 썸네일의 워터마크를 한글로 찍어보고 싶어서 만든겁니다.
수정이 필요한 부분만 굵게 표시를 해뒀으니, 참조해서 수정하시면 됩니다.

ttf 파일은 한겨레신문에서 공개한 것을 사용합니다. 다른 것은 이런저런 이슈가 많더라구요.

* 균이님과 phpschool에서 정보를 공개해주신 분들께 감사드립니다.


write_update.skin.php에서

<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

include_once("$board_skin_path/skin.lib.php");

list($img_width, $img_height) = explode("x", $board[bo_1]);
list($img2_width, $img2_height) = explode("x", $board[bo_2]);
$img_quality = 100;

$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';

if ($_FILES[bf_file][name][0]) {
    $row = sql_fetch(" select * from $g4[board_file_table] where bo_table = '$bo_table' and wr_id = '$wr_id' and bf_no = '0' ");

    $file = $data_path .'/'. $row[bf_file];

    if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file)) {
        $thumb_file = "{$thumb_path}/{$wr_id}";
        $size = getimagesize($file);
        if ($size[2] == 1)
            $src = imagecreatefromgif($file);
        else if ($size[2] == 2)
            $src = imagecreatefromjpeg($file);
        else if ($size[2] == 3)
            $src = imagecreatefrompng($file);
        else
            break;
           
        /*
        if ($size[0] > $size[1]) {
            $rate = $board[bo_1] / $size[0];
            $height = (int)($size[1] * $rate);
            $img_width = $board[bo_1];
            $img_height = $height;
        } else {
            $rate = $board[bo_1] / $size[1];
            $width = (int)($size[0] * $rate);
            $img_width = $width;
            $img_height = $board[bo_1];
        }
        */
       
        if ($size[0] > $size[1]) {
                if($size[0] < $board[bo_1]) {
                    $img_width = $size[0];
                    $img_height = $size[1];
                } else {
                    $rate = $board[bo_1] / $size[0];
                    $height = (int)($size[1] * $rate);

                    $img_width = $board[bo_1];
                    $img_height = $height;
                }
            } else {
                if($size[1] < $board[bo_1]) {
                    $img_width = $size[0];
                    $img_height = $size[1];
                } else {
                    $rate = $board[bo_1] / $size[1];
                    $width = (int)($size[0] * $rate);
                    $img_width = $width;
                    $img_height = $board[bo_1];
                }
            }
       
        createThumb2($img_width, $img_height, $file, $thumb_file, $member[mb_nick]);
       
        $thumb_file = "{$thumb_path}/{$wr_id}_{$img2_width}x{$img2_height}";
        createThumb($img2_width, $img2_height, $file, $thumb_file);

        $sql = " update $write_table set wr_10 = '$exif[Model]' where wr_id = '$wr_id' ";
        sql_query($sql);
    }
}
?>


skin.lib.php에서

<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

if (!function_exists("createThumb")) {
    // 원본 이미지를 넘기면 비율에 따라 썸네일 이미지를 생성함
    function createThumb($imgWidth, $imgHeight, $imgSource, $imgThumb='') {
        if (!$imgThumb)
            $imgThumb = $imgSource;

        //@unlink($imgSource); // 원본 이미지 파일명
        //echo $imgSource; exit;

        $size = getimagesize($imgSource);
        if ($size[2] == 1)
            $source = imagecreatefromgif($imgSource);
        else if ($size[2] == 2)
            $source = imagecreatefromjpeg($imgSource);
        else if ($size[2] == 3)
            $source = imagecreatefrompng($imgSource);
        else
            return 0;

        $rate = $imgWidth / $size[0];
        $height = (int)($size[1] * $rate);

        if ($size[0] < $imgWidth || $size[1] < $imgHeight) {
            $xWidth = $imgWidth;
            $xHeight = $imgHeight;
            $height = $imgHeight;
        } else {
            $xWidth = $size[0];
            $xHeight = $size[1];
        }

        $target = @imagecreatetruecolor($imgWidth, $imgHeight);
        $white = @imagecolorallocate($target, 255, 255, 255); 
        @imagefilledrectangle($target, 0, 0, $imgWidth, $imgHeight, $white);
        @imagecopyresampled($source, $source, 0, 0, 0, 0, $imgWidth, $height, $xWidth, $xHeight);
        @imagecopy($target, $source, 0, 0, 0, 0, $imgWidth, $imgHeight);

        @imagejpeg($target, $imgThumb, 100);
        @chmod($imgThumb, 0606); // 추후 삭제를 위하여 파일모드 변경
    }
}

// 원본 이미지를 넘기면 비율에 따라 썸네일 이미지를 생성함
function createThumb2($imgWidth, $imgHeight, $imgSource, $imgThumb='', $mb_nick) {
    global $g4;

    if (!$imgThumb)
        $imgThumb = $imgSource;

    $size = getimagesize($imgSource);
    if ($size[2] == 1)
        $source = imagecreatefromgif($imgSource);
    else if ($size[2] == 2)
        $source = imagecreatefromjpeg($imgSource);
    else if ($size[2] == 3)
        $source = imagecreatefrompng($imgSource);
    else
        return 0;

    $rate = $imgWidth / $size[0];
    $height = (int)($size[1] * $rate);

    $target = @imagecreatetruecolor($imgWidth, $imgHeight);
    //@imagecolorallocate($source, 255, 255, 255);
    @imagecopyresampled($source, $source, 0, 0, 0, 0, $imgWidth, $height, $size[0], $size[1]);
    @imagecopy($target, $source, 0, 0, 0, 0, $imgWidth, $imgHeight);
    //$white = imagecolorallocate($target, 255, 255, 255);
    $white = imagecolorallocate($target, 150, 150, 150);
    $black = imagecolorallocate($target, 100, 100, 100);
    $margin=0;
    $n=0;
    for ($y=5;$y<$imgHeight;$y+=70) {
        for ($x=5;$x<$imgWidth;$x+=120) {
            $string = ($n%2) ? "$_SERVER[SERVER_NAME]" : $mb_nick;
            $color = ($n%2) ? $white : $black;
            //imagestring($target, 1, $x+$margin, $y, $string, $color);
            imagettftext($target, 6, 0, $x+$margin, $y, $color, "$g4[path]/img/han.ttf", iconv("EUC-KR", "UTF-8", "$string") );
            $n++;
        }
        $margin+=5;
    }
    //@imagettftext($target, 20, 0, 10, 20, $white, "$g4[path]/img/arialbd.ttf", "sir.co.kr");
    /*
    $font=ImagePsLoadFont("$g4[path]/img/cibt____.pfb");
    ImagePsText($target, "Testing... It worked!", $font, 32, $white, $white, 32, 32);
    ImagePsFreeFont($font);
    */
    @imagejpeg($target, $imgThumb, 100);
    @chmod($imgThumb, 0606); // 추후 삭제를 위하여 파일모드 변경
}
?>

첨부파일

댓글목록

등록된 댓글이 없습니다.

PHP
871 (8/18P)

Search

Copyright © Cmd 명령어 18.191.175.156